package com.huige.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.huige.mapper.EmpMapper;
import com.huige.pojo.Emp;
import com.huige.pojo.PageBean;
import com.huige.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * ClassName: EmpServiceImpl
 * Package: com.huige.service.impl
 * Description:
 *
 * @Author 朱志辉
 * @Create 2024/5/3 14:58
 * @Version 1.0
 */
@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;

/*    @Override
    public PageBean page(Integer page, Integer pageSize) {
        //1.获取总记录数
        Long count = empMapper.count();
        //2.获取分页查询的结果列表
        Integer start = (page - 1) * pageSize;
        List<Emp> empList = empMapper.page(start, pageSize);

        //3.封装PageBean对象
        PageBean pageBea = new PageBean(count, empList);
        return pageBea;
    }*/


    @Override
    public PageBean page(Integer page, Integer pageSize, String name, Short gender, LocalDate begin, LocalDate end) {
        //1.设置分页参数
        PageHelper.startPage(page, pageSize);
        //2.执行正常查询操作
        List<Emp> empList = empMapper.list(name,gender,begin,end);
        Page<Emp> p = (Page<Emp>) empList;
        //3.封装PageBean对象
        return new PageBean(p.getTotal(), p.getResult());
    }

    @Override
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }

    @Override
    public void add(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.add(emp);
    }



    @Override
    public Emp getById(Integer id) {
       return empMapper.getById(id);
    }

    @Override
    public void upDate(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.upDate(emp);
    }

    @Override
    public Emp login(Emp emp) {
        return empMapper.getByUsernameAndPassword(emp);
    }


}
